/**
 *
 */
package com.wedroid.r2d2.message.parser;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import com.wedroid.entity.message.MessageType;
import com.wedroid.r2d2.message.RawMessage;
import com.wedroid.r2d2.utils.XmlStringUtils;

/**
 * @author lute
 */
@Component("emoticonContentParser")
public class EmoticonContentParser implements ContentParser {

    /* (non-Javadoc)
     * @see com.wedroid.r2d2.message.parser.ContentParser#supportsMessageType(com.wedroid.entity.message.MessageType)
     */
    public boolean supportsMessageType(MessageType messageType) {
        return MessageType.EMOTICON.equals(messageType);
    }

    /* (non-Javadoc)
     * @see com.wedroid.r2d2.message.parser.ContentParser#parse(com.wedroid.r2d2.message.RawMessage, java.lang.String)
     */
    public String parse(RawMessage rawMessage, String escapedContent) {
        String data = XmlStringUtils.findAttribute("cdnurl", escapedContent);
        if (StringUtils.isBlank(data)) {
            return "[Received a sticker. View on phone]";
        }
        return data;
    }

}
